<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('卡信息')">
              <a-input :placeholder="$t('请输入卡号/姓名')" v-model="queryParam.cardInfo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('账户状态')">
              <a-select v-model="queryParam.state">
                <a-select-option :value="item.value" :key="index" v-for="(item, index) in paytypeList">{{
                  item.title
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('卡类型')">
              <j-dict-select-tag :placeholder="$t('请选择')" v-model="queryParam.cardKind" dictCode="bis_system_card.card_kind"/>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
            </span>
          </a-col>
          <template v-if="toggleSearchStatus"> </template>
        </a-row>
      </a-form>
    </div>
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <span  v-if="record.cardKind != '1'">
            <a-popconfirm
              v-if="record.state == '0'"
              :title="$t('card-loss',{cardSn:record.cardSn})"
              @confirm="() => changeCardState(record, 1)"
              v-has="'BisSystemCardController:edit'"
            >
              <a>{{$t('挂失')}}</a>
            </a-popconfirm>
            <a-popconfirm
              v-if="record.state == '1'"
              :title="$t('card-unloss',{cardSn:record.cardSn})"
              @confirm="() => changeCardState(record, 0)"
              v-has="'BisSystemCardController:edit'"
            >
              <a>{{$t('解挂')}}</a>
            </a-popconfirm>
          </span>
          <a @click="operationRecord(record)" style="margin-left: 8px">{{$t('操作记录')}}</a>
        </span>
      </a-table>
    </div>

    <operation-record-modal ref="operationForm"></operation-record-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import { putAction } from '@/api/manage'
import OperationRecordModal from './modules/OperationRecordModal'

export default {
  name: 'SystemManageCard',
  mixins: [JeecgListMixin],
  components: {
    OperationRecordModal,
  },
  data() {
    return {
      description: this.$t('系统管理卡'),
      queryParam: {
        cardInfo: '',
        state: '',
      },
      // 表头
      columns: [
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'cardSn',
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('卡类型'),
          align: 'center',
          dataIndex: 'cardKind_dictText',
        },
        {
          title: this.$t('账户状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('卡状态'),
          align: 'center',
          dataIndex: 'cardState_dictText',
        },
        {
          title: this.$t('制卡时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          width: '100',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/system/bisSystemCard/list',
      },
      paytypeList: [],
      typeList: [],
      activeKey: '0',
      ipagination1: {
        current: 1,
        pageSize: 30,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + this.$t('sum-total',{total:total})
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
    }
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      initDictOptions('bis_system_card.state').then((res) => {
        if (res.success) {
          this.paytypeList = res.result
          this.paytypeList.unshift({ value: '', title: this.$t('全部') })
        }
      })
    },
    changeCardState(record, state) {
      let query = Object.assign({}, record)
      query.state = state
      putAction('/system/bisSystemCard/edit', query).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData(1)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    operationRecord(record) {
      this.$refs.operationForm.edit(record)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>